const app = getApp(); //引入导航
var util = require('../../utils/common.js'); //引入公共JS
import { MySearch } from '../mySearch/mySearch.model.js';
var search = new MySearch();
import { Mine } from 'mine.model.js';
import { Submit } from '../SubmitYcOrder/SubmitYcOrder_model.js';
var submit = new Submit();
var mine = new Mine();
Page({
  data: {
    lineLogin: true,
  },
  onLoad: function () {
     
    // 查看是否授权用户信息
    var userinfo = tt.getStorageSync('userInfo');
    if (userinfo) {
      this.setData({
        'userInfo': JSON.parse(userinfo),
        'lineLogin': false,
      });
    }

    var that =this
    tt.getSetting({
      success(res){
        console.log(res)
        if(!res.authSetting['scope.userInfo']){
          tt.authorize({
          scope: "scope.userInfo",
          success() {
            that.getUserInfo()
          },
        });
        }
      }
    });

  },
  //底部拨打电话
  calling: function () {
    util.calling();
  },
  //分享
  onShareAppMessage: function () {
    util.sharePage();
  },

  // 判断是否登录
  getUserProfile(e) {
    const url = e.currentTarget.dataset.url
    // 判断是否登录
    if(tt.getStorageSync('token')){
      tt.navigateTo({
        url: url// 指定页面的url
      });
    }else{
      util.login(url)
    }
  },

  // 获取头像信息
  getUserInfo(){
    console.log('头像')
    var that=this
    tt.getUserInfo({
      withCredentials: true,
      success(res) {
        console.log(`getUserInfo 调用成功 `,res.rawData);
        tt.setStorageSync('userInfo', res.rawData);
        var userinfo = JSON.parse(res.rawData)
        console.log(that.data.lineLogin,userinfo)
        that.setData({
          'userInfo':userinfo,
          'lineLogin': false,
        });
      },
      fail(res) {
        console.log(`getUserInfo 调用失败`);
      },
    });
  }
});